package interfaces.spawnMenu.spawnMap;

import com.jme.system.DisplaySystem;

import interfaces.ImageUpdater;
import logic.common.player.Player;
import logic.ships.carrier.Carrier;
import logic.ships.frigate.Frigate;
import logic.ships.hunter.Hunter;
import logic.ships.moveableShip.MovableShip;

public class ShipMapIcon extends MiniMapIcon {

	private final int HUNTER_FACTOR = 70;
	private final int CARRIER_FACTOR = 50;
	private final int FRIGATE_FACTOR = 40;
	
	private final String ENEMY = "Enemy";
	private final String FRIENDLY = "Friendly";
	private final String PLAYER = "Player";
	
	protected MovableShip ship;
	protected String iconPath;
	protected ImageUpdater imageUpdater;
	
	public ShipMapIcon(MovableShip ship, Player player, int x, int y) {
		super(0, 0, x, y);
		this.ship = ship;
		
		iconPath = "data/textures/gui/miniMap/";
		int size = DisplaySystem.getDisplaySystem().getHeight();
		
		if(ship instanceof Hunter) {
			iconPath += "hunter";
			size /= HUNTER_FACTOR;
		} else if(ship instanceof Frigate) {
			iconPath += "frigate";
			size /= FRIGATE_FACTOR;
		} else if(ship instanceof Carrier) {
			iconPath += "carrier";
			size /= CARRIER_FACTOR;
		}
		
		setSize(size, size);
		
		boolean friendly = player.getTeam() == ship.getTeam();
		
		String friendMode = (friendly ? FRIENDLY : ENEMY);
		if(ship instanceof Hunter) {
			Hunter hunter = (Hunter)ship;
			Player pilot = hunter.getPilot();
			if(pilot.isHuman() && pilot == player) friendMode = PLAYER;
		}
		
		iconPath += "Icon" + friendMode + ".png";
		
		imageUpdater = new ImageUpdater(iconPath, 0, 0, size, size);
		addWidget(imageUpdater);
		
		layout();
	}
}